package cn.com.sparkle.paxos;

import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;

import cn.com.sparkle.paxos.net.NetNode;

public class NodesCollection {
	private Set<ConfigNode> nodeMembers;
	private Set<NetNode> activeNodes;
	private Map<String, NodeState> nodeStates;
	// this unordered list can reduce the pressure of single active senator
	private LinkedList<NetNode> outOfOrderList;

	public NodesCollection(Set<ConfigNode> nodeMembers,
			Set<NetNode> activeNodes, Map<String, NodeState> nodeStates) {
		super();
		this.nodeMembers = nodeMembers;
		this.activeNodes = activeNodes;
		this.nodeStates = nodeStates;
		LinkedList<NetNode> l = new LinkedList<NetNode>();
		for (NetNode n : activeNodes) {
			l.add(n);
		}
		Collections.shuffle(l);
		this.outOfOrderList = l;
	}

	public Set<ConfigNode> getNodeMembers() {
		return nodeMembers;
	}

	public Set<NetNode> getActiveNodes() {
		return activeNodes;
	}

	public LinkedList<NetNode> getOutOfOrderList() {
		return outOfOrderList;
	}

	public Map<String, NodeState> getNodeStates() {
		return nodeStates;
	}

}
